#include "nstar_adt_httputil.h"
#include "nstar_adt_http_page.h"



#define C_PAGE_NAME HTML_PAGE2_NAME

#define C_PAGE_BODY_0 "<style>label1{display: inline-block;}</style>"\
"<body>"\
"<ul>"\
"<li><a class='home'>康拓-KTYX</a></li>"\
"<li><a href='"HTML_PAGE1_NAME".html'>模拟状态</a></li>"\
"<li><a href='"HTML_PAGE2_NAME".html' class='active'>模拟输入</a></li>"\
"<li><a href='"HTML_PAGE3_NAME".html'>故障记录</a></li>"\
"<li><a href='"HTML_PAGE4_NAME".html'>OEM信息</a></li>"\
"</ul>"\
"<h2> chengdu kangte web management interface </h2>"\
"<h3> 模拟输入</h3>"\
"<div style='background:snow; display:block; padding:10px 10%;'>"\
"<form id='frmSetting' method='POST' action='"C_PAGE_NAME".cgi'>"\

#define C_PAGE_BODY_2 "<p><p><input type='button' value='保存' onclick ='commit();'  id='rcorners1'/>"\
"<input type='button' onclick ='savereboot();' value='重启终端' id='rcorners1' style='background: #ff6300'/></p>"\
"</form>"\
"</div>"\
"</body>"\
"</html>"


static struct js_node list[] = {
    {"启停按钮", 26, 0, NULL, NULL, &gbsp.key, 4, "0：停止，1：启动"},
    {"压缩机1控制故障", 26, 0, NULL, NULL, &gbsp.err_compar1, 4, "0：正常，1：异常"},
    {"压缩机2控制故障", 26, 0, NULL, NULL, &gbsp.err_compar2, 4, "未配置，已屏蔽"},
    {"切换阀1控制故障", 26, 0, NULL, NULL, &gbsp.err_sov1, 4, NULL},
    {"切换阀2控制故障", 26, 0, NULL, NULL, &gbsp.err_sov2, 4, NULL},
    {"机上告警控制故障", 26, 0, NULL, NULL, &gbsp.err_alrc, 4, NULL},
    {"压缩机工况", 26, 0, NULL, NULL, &gbsp.compr_sta, 4, "111：待机，110：工作，其他：异常"},
    {"温度传感器故障", 26, 0, NULL, NULL, &gbsp.hp203_err, 4, NULL},
    {"高度", 26, 0, NULL, NULL, &gbsp.hp203_altitude, 4, NULL},   
    {"温度", 26, 0, NULL, NULL, &gbsp.hp203_temp, 4, NULL},  
    {"氧传感器故障", 26, 0, NULL, NULL, &gbsp.oxy_cap_err, 4, NULL}, 
    {"氧分压值", 26, 0, NULL, NULL, &gbsp.oxy_cap_data, 4, "下限:1100, 过低：1600，上限:11000"},
    {NULL},
};

static void _add_htm_element(unsigned char mode)
{
	unsigned int sip,dip;
    const unsigned char *lip, *mask, *gw, *otaip;
	unsigned short sport,dport,otaport;
	unsigned char *id;
	if(mode == URI_REPOS_HTML){
		list_htm_jsreq(&list);
	}
	else if(mode == URI_REPOS_JSON){
	    list_htm_jsrepos(&list);
	}
}

void http_page_htm2(const char *name, void (fun_add_elemnet)(unsigned char))
{
	http_sprintf_init();
	http_sprintf("%s%s", HTML_PARM_HEAD, C_PAGE_BODY_0);
    list_htm_body(&list);
    http_sprintf("%s", C_PAGE_BODY_2);
	http_sprintf(REQUST_JSCRIPT_HEAD, name);
	fun_add_elemnet(URI_REPOS_HTML);
	REQUST_JSCRIPT_END(name);
	http_sprintf_send();
}


void parm2_pos_htm(unsigned char mode)
{
	if(mode == URI_REPOS_HTML) {
        http_page_htm2(C_PAGE_NAME, _add_htm_element);
	}
	else if(mode == URI_REPOS_JSON) {
		http_page_json(C_PAGE_NAME, _add_htm_element);
	}
}


void parm2_rpos_cgi(char *url)
{ 
	char *p_content; 
	p_content = (char*)my_get_param_url(url);
	if(NULL == p_content) {
		return;
	}
    list_htm_ack(&list, p_content, HTM_CMM_ACK);
	http_sprintf_init();
	http_sprintf(HTML_CGI_JUMP, "127.0.0.1", C_PAGE_NAME);
	http_sprintf_send();
}

void rpos_reboot_cgi(void)
{ 
	http_sprintf_init();
	http_sprintf(HTML_CGI_JUMP, "127.0.0.1", C_PAGE_NAME);
	http_sprintf_send();
}


